import java.util.Arrays;

public class MyArrayList {
    private int[] elem;
    private int usedSize;
    private static final int DEFAULT_SIZE = 6;

    public MyArrayList() {
        this.elem = new int[DEFAULT_SIZE];
    }

    public void display () {
        for (int i = 0; i <= this.usedSize - 1; i++) {
            System.out.print(this.elem[i] + " ");
        }
    }

    public int size() {
        return this.usedSize;
    }

    public boolean isFull() {
        if (size() >= this.elem.length) {
            return true;
        }
        return false;
    }

    public void add(int data) {
        //判断顺序表是否已满，满了则扩容
        if (isFull()) {
            this.elem =
                    Arrays.copyOf(this.elem, 2 * this.elem.length);
        }
        this.elem[this.usedSize] = data;
        usedSize++;
    }
}
